package day7;

import java.util.Scanner;

//Fibonacci数列
public class oj2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();
        int f1 = 0;
        int f2 = 1;
        int f3 = 1;
        while(f2 < n) {
            f3 = f2 + f1;
            f1 = f2;
            f2 = f3;
        }
        int x = Math.min(n-f1,f2-n);
        System.out.println(x);
    }
}
